package com.lz.timer.an;

import com.lz.mongo.MongoUtilFactory;
import com.lz.timer.an.common.Config;
import com.lz.zookeeper.ZooKeeperClient;
import com.lz.zookeeper.ZooKeeperUtil;

import lombok.extern.slf4j.Slf4j;

/**
 * 应用初始化及销毁
 *
 * @author rench
 */
@Slf4j
public class Init {

    /**
     * 获取zk实例
     */
    private final static ZooKeeperClient ZOOKEEPERCLIENT = ZooKeeperClient.getInstance(Config.ZK_SERVER_PATH, Config.ZK_CONFIG_PATH, Config.class);

    public static void init() throws Exception {
        log.debug("======================" + Init.class + " init()========================");
        ZooKeeperUtil.startupZk(ZOOKEEPERCLIENT, "");

        MongoUtilFactory.mongoUtil1().init();
    }

    public static void destroy() throws Exception {
        log.debug("======================" + Init.class + " destroy()========================");
        ZooKeeperUtil.shutdownZk(ZOOKEEPERCLIENT);

        MongoUtilFactory.mongoUtil1().close();
    }
}

